import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { visualizer } from 'rollup-plugin-visualizer'
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue(), visualizer({ open: true })],
  base: "./",
  resolve: {
    // alias: {
    //     '@': pathResolve('src'),
    //     "comps": pathResolve("src/components"),
    //     "@views": pathResolve( "src/views"),
    // },
  },
  optimizeDeps: {
    include: ["axios"],
  },
  build: {
    target: "modules",
    outDir: "dist",
    assetsDir: "assets",
    cssCodeSplit: true,
    minify: "terser", // 混淆器
    terserOptions: {
      compress: {
        drop_console: true,
        drop_debugger: true,
      },
    },
    rollupOptions: {
      external: ["vue", "element-plus", "vue-router"], //告诉打包工具 在external配置的 都是外部依赖项  不需要打包
      output: {
        manualChunks(id) {
          if (id.includes("node_modules")) {
            // 让每个插件都打包成独立的文件
            return id
              .toString()
              .split("node_modules/")[1]
              .split("/")[0]
              .toString();
          }
        },
      },
    },
  },
  server: {
    cors: true,
    open: true,
    host: "0.0.0.0", // 允许外部IP访问
    port: 8080, // 自定义端口
    proxy: {
      "/api": {
        target: "http://192.168.165.142:20001", //代理接口
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
    },
  },
});
